package com.zy.web.controller.bs;

import com.zy.pojo.vos.bs.ClubSetWizardsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zy.entity.bs.Club;
import com.zy.pojo.query.bs.ClubQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.ClubService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.List;

@RequestMapping({"bs/club","m/bs/club"})
@Controller
public class ClubController extends BaseController {

	@Autowired
	private ClubService clubService;

	/**
	 * 分页
 	 * 
 	 * @param clubQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageClub")
	@ResponseBody
	public PageVo pageClub(ClubQuery clubQuery, Integer start, Integer limit) {
		return this.clubService.pageClub(clubQuery, start, limit);
	}
	/**
	 * 新增
	 *
	 * @param club
	 * @return
	 */
	@RequestMapping(value = "saveClub", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveClub(List<MultipartFile> clubImgs, Club club) {
		try {
			this.clubService.saveClub(clubImgs,club);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 更新
	 *
	 * @param club
	 * @return
	 */
	@RequestMapping(value = "updateClub", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateClub(List<MultipartFile> clubImgs,Club club) {
		try {
			this.clubService.updateClub(clubImgs,club);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 *
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeClub", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeClub(long id) {
		try {
			this.clubService.removeClub(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 *
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.clubService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 首页热门俱乐部
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping(value = "front/pageClubForHomePage", method = RequestMethod.POST)
	@ResponseBody
	public PageVo pageClubForHomePage(Integer start, Integer limit) {
		return this.clubService.pageClubForHomePage(start, limit);
	}

    @RequestMapping("getMyClub")
    @ResponseBody
    public ResultVo getMyClub() {
        try {
            return ResultUtil.success(  (Serializable) this.clubService.getMyClub(this.getCurrentUser().getId()));
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }

    }

    @RequestMapping("getClubInfo")
    @ResponseBody
    public ResultVo getClubInfo(Long id) {
        try {
            return ResultUtil.success(clubService.getClubInfo(id));
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }

    @RequestMapping(value = "updateClubSetWizards", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo updateClubSetWizards(ClubSetWizardsVo clubSetWizardsVo) {
        try {
            this.clubService.updateClubSetWizards(clubSetWizardsVo);
            return ResultUtil.success();
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }
    @RequestMapping("getMyClubManager")
    @ResponseBody
    public ResultVo getMyClubManager() {
        try {
            return ResultUtil.success(  (Serializable) this.clubService.getMyClubManager(this.getCurrentUser().getId()));
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }

    }

    @RequestMapping("front/pageClub")
    @ResponseBody
    public PageVo homePage(ClubQuery clubQuery, Integer start, Integer limit) {
        return this.clubService.pageClub(clubQuery, start, limit);
    }

}